<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="res/lib/zepto.min.js"></script>
</head>
<body>
<script>
              function setCookie(name,value,time)
              {
                  var Days = time;
                  var exp = new Date();
                  exp.setTime(exp.getTime() + Days*24*60*60*1000);
                  document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
              }
              function getCookie(name)
              {
                  var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
                  if(arr=document.cookie.match(reg))
                      return unescape(arr[2]);
                  else
                      return null;
              }
    if(!getCookie('access_token')) {
        $.ajax({
            url: "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxaa1f342551a5902b&secret=5ab88302417be1e1a47daa33c50eeee5",
            type: "get",
            success: function (res) {
                console.log(res,res.access_token)
                setCookie('access_token', res.access_token, 0.08)
                if(!getCookie('ticket')) {
                    $.ajax({
                        url: "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+getCookie('access_token')+"&type=jsapi",
                        type: "get",
                        success: function (res) {
                            console.log(res)
                            setCookie('ticket', res.access_token, 0.08)
                        }
                    })
                }
            }
        })
    }
    if(!getCookie('ticket')&&getCookie('access_token')) {
                  $.ajax({
                      url: "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+getCookie('access_token')+"&type=jsapi",
                      type: "get",
                      success: function (res) {
                          console.log(res)
                          //setCookie('ticket', res.access_token, 0.08)
                          $('body').append(res)
                      }
                  })
    }




</script>
</body>
</html>